const koaRouter = require('@koa/router')
const { verifAuth } = require('../middleware/login.middleware')
const { create, list, detail, updated, remove, addLabels } = require('../controller/moment.controller')
const { verifPermission } = require('../middleware/verifMomentPermission.middleware')
const { verifLabelsExist } = require('../middleware/label.middleware')

const momentRouter = new koaRouter({ prefix: '/moment' })
// 增加
momentRouter.post('/', verifAuth, create)
// 查
momentRouter.get('/', list)
momentRouter.get('/:momentId', detail)
// 改
momentRouter.patch('/:momentId', verifAuth, verifPermission, updated)
// 删
momentRouter.delete('/:momentId', verifAuth, verifPermission, remove)
// 为moment添加标签
/* 
    1.是否登陆
    2.验证登陆用户是否有添加标签的权限
    3.额外中间件，验证label的name是否已经添加到数据库
    *如果存在，直接使用
    *不存在，添加到数据库
    4.最终步骤
    *所有的labels都已经在label表
    *动态2，和label的关系，添加到关系表
*/
momentRouter.post('/:momentId/labels', verifAuth, verifPermission, verifLabelsExist, addLabels)
module.exports = momentRouter